﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AnesSystem.Models;

namespace AnesSystem.Controls
{
    /// <summary>
    /// WCSSYCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class WCSSYCtrl : RealVitalIcon
    {
        public WCSSYCtrl()
        {
            InitializeComponent();
            DefaultColor= Brushes.Black;
            ResizeIcon();
        }

        public override void ResizeIcon()
        {
            Brush color = Brushes.Black;
            Line line1 = new Line();
            line1.X1 = 0;
            line1.Y1 = Height * 0.2;

            line1.X2 = this.Width / 2;
            line1.Y2 = this.Height;
            line1.Stroke = color;
            line1.StrokeThickness = 1;
            _grid.Children.Add(line1);

            Line line2 = new Line();
            line2.X1 = this.Width;
            line2.Y1 = Height * 0.2;

            line2.X2 = this.Width / 2;
            line2.Y2 = this.Height;
            line2.Stroke = color;
            line2.StrokeThickness = 1;
            _grid.Children.Add(line2);
        }

        public override void CalculateXY()
        {
            X1 = CanvasLeft + this.Width / 2;
            Y1 = CanvasTop + this.Height;
            X2 = X1;
            Y2 = Y1;
            LeftPoint = new Point(X1, Y1);
            RightPoint = new Point(X2, Y2);
        }

        protected override int CalValue2Yplot(PatientVitalSignsModel iItem)
        {

            if (string.IsNullOrEmpty(iItem.ModValue)) return 0;
            double value = Convert.ToDouble(iItem.ModValue);
            double lineHeight = LocationUtil.RealTimeSignItem_TotalRows * LocationUtil.RealTimeSignItem_Height;
            return CheckValue2Yplot( Convert.ToInt32(lineHeight - lineHeight / LocationUtil.SignEnd_Value * value - this.Height));

        }
        public override double CalY2Valueplot(double top)
        {
            double lineHeight = LocationUtil.RealTimeSignItem_TotalRows * LocationUtil.RealTimeSignItem_Height;
            return CheckY2Valueplot( Convert.ToInt32(LocationUtil.SignEnd_Value - LocationUtil.SignEnd_Value / lineHeight * (top + this.Height)));  
        }
        public override double CheckY2Valueplot(double value)
        {
            if (value < 0)
            {
                return 0;
            }
            else if (value > 280)
            {
                return 280;
            }
            else
            {
                return value;
            }
        }
        public override int CheckValue2Yplot(int y)
        {
            if (y < 0)
            {
                return 0;
            }
            else if (y > LocationUtil.RealTimeSignItem_Height * LocationUtil.RealTimeSignItem_TotalRows)
            {
                return LocationUtil.RealTimeSignItem_Height * LocationUtil.RealTimeSignItem_TotalRows;
            }
            else
            {
                return y;
            }
        }
    }
}
